<?php

namespace app\index\service;

use app\common\GHttp;

class Weather
{
    protected $url = 'https://free-api.heweather.net/s6/weather/?key=';
    protected $key;

    public function __construct($key)
    {
        $this->key = $key;
    }

    /**
     * 获取天气信息
     * @param string $ip
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getInfo($ip = '')
    {
        return GHttp::getJson($this->url . $this->key . (!empty($ip) ? '&location=' . $ip : ''));
    }
}